<template>
  <div class="pinglun" @scroll="gun" ref="gunju">
     <div class="centent" v-for="(item,index) in pinglun" :key="index">
       <img :src="item.userInfo.avatar" alt="">

       <div class="author">
         <div class="author-top">
            <span>{{item.userInfo.username}}</span>
            <img v-if="item.userInfo.vip_status===1" src="../assets/vip.png" alt="">
         </div>
         <p class="p1" style="white-space:pre-wrap">{{item.content}}</p>
         <p class="p2">{{date[index]}}</p>
       </div>

       <div class="img">
         <img class="tu1" src="../assets/评论小.png" alt="">
         <img class="tu2" src="../assets/点赞黑.png" alt="">
         <span>0</span>
       </div>
     </div>
  </div>
</template>

<script>
export default {
  created(){
    this.getpinglun(this.$route.query.id,this.page)
  },
  data(){
    return{
       page:1,
       pinglun:[],
       date:[]
    }
  },
  methods:{
    //滚动的距离
    gun(){
      if(this.$refs.gunju.scrollHeight-this.$refs.gunju.scrollTop===this.$refs.gunju.clientHeight){
        
        this.page++
        this.getpinglun(this.$route.query.id, this.page)
      }
    },
    getpinglun(id,page){
       this.axios({
         method:'get',
         url:'https://apis.netstart.cn/xpc/comments?',
         params:{
           resource_id:id,
           type:'article',
           page:page
         }
       }).then(result=>{
         this.pinglun=result.data.data.list
        
         this.pinglun.forEach(v=> {
            let date=new Date(v.addtime*1000)
            this.date.push(date.toLocaleString().substring(0,9).replaceAll("/","-"))
         });
       }).catch(err=>{
         
       })
    }
  }
}
</script>

<style lang="less" scoped>
.pinglun{
  width: 100%;
}
.centent{
  width: 100%;
  height: 100px;
  display: flex;
  border-bottom: 1px solid #ddd;
  img{
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 1px solid #ddd;
    margin-left: 10px;
    margin-top: 10px;
  }
  .author{
    width: 250px;
    height: 90px;
    margin-left: 10px;
  
    .author-top{
      width: 200px;
      height: 30px;
      display: flex;
      align-items: center;
      span{
        font-size: 12px;
      }
      img{
      width: 20px;
      height: 20px;
      margin-top: -3px;
      margin-left: 0px;
      }
    }
    .p1{
      margin-top: 0px;
      font-size: 14px;
       text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    }
  }
  .img{
    width: 70px;
    height: 30px;
    display: flex;
    align-items: center;
    margin-top: 50px;
    
    .tu1{
      border-radius: 0%;
      border: 1px solid transparent;
      width: 15px;
      height: 15px;
      margin-left: 0px;
    }
    .tu2{
      border-radius: 0%;
      border: 1px solid transparent;
      width: 18px;
      height: 18px;
      margin-left:16px;
    }
    span{
      margin-left: 0px;
      margin-top: 13px;
    }
  }
}
</style>